
const sendMessage = async (chatObj) => {
    //校验各个参数
    if (!chatObj.chatList) {
        throw new Error('message is required');
    }
    if (!chatObj.apiKey) {
        throw new Error('apiKey is required');
    }
    if (!chatObj.chatList.length) {
        throw new Error('message is empty');
    }
    if (chatObj.chatList.length > 36) {
        throw new Error('message is too long');
    }

    try {
        const res = await window.electron.ipcRenderer.invoke('send-message', chatObj);
        return res;
    } catch (error) {
        console.log(error);
        const baseStr = "Error invoking remote method 'send-message': Error: "
        const startIndex = error?.message?.indexOf(baseStr) + baseStr.length;
        const endIndex = error?.message?.length;
        const errorContent = error?.message?.substring(startIndex, endIndex);
        throw new Error(errorContent);
    }

};

export { sendMessage };